// 图片添加水印
export const addWaterMark=(tempFilePath)=> {
	return new Promise((resolve, reject) => {
		let that = this
		wx.createSelectorQuery().select('#mycanvas').fields({
			node: true,
			size: true
		}).exec((res) => {
			const canvas = res[0].node;
			const ctx = canvas.getContext('2d');
			const imageSrc = tempFilePath; // 替换为你的图片路径
			wx.getImageInfo({
				src: imageSrc,
				success: function(imageRes) {
					canvas.width = imageRes.width; // 设置 canvas 宽度为图片宽度
					canvas.height = imageRes.height; // 设置 canvas 高度为图片高度

					// 图片对象
					const image = canvas.createImage()
					// 图片加载完成回调
					image.onload = () => {
						// 将图片绘制到 canvas 上
						ctx.drawImage(image, 0, 0)
						ctx.font = '30px Arial';
						ctx.fillStyle = 'red';
						ctx.strokeStyle = "black";
						// 图片加地点
						ctx.fillText(that.data.address, 10, imageRes.height - 20);

						// 将 canvas 导出成临时图片文件
						setTimeout(() => {
							wx.canvasToTempFilePath({
								canvas: canvas,
								success: function(res) {
									// 输出生成的带水印的图片临时路径
									resolve(res.tempFilePath)
								},
								fail: function(res) {
									reject(res)
									console.error(res);
								}
							});
						}, 1000);
					}
					image.src = imageSrc
				},
				fail: function(imageRes) {
					console.error(imageRes);
				}
			});
		});
	})
},